package com.retirement.trusteeship.service.impl;

import cn.hutool.core.util.IdUtil;
import com.retirement.common.utils.SecurityUtils;
import com.retirement.staff.mapper.OldStaffMapper;
import com.retirement.trusteeship.domain.OldTrusteeship;
import com.retirement.trusteeship.dto.OldTrusteeshipDto;
import com.retirement.trusteeship.mapper.OldTrusteeshipMapper;
import com.retirement.trusteeship.service.IOldTrusteeshipService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lijy
 * @since 2024-01-03
 */
@Service
public class OldTrusteeshipServiceImpl extends ServiceImpl<OldTrusteeshipMapper, OldTrusteeship> implements IOldTrusteeshipService {

    @Resource
    private OldStaffMapper oldStaffMapper;

    @Override
    public List<OldTrusteeship> listTrusteeship(OldTrusteeshipDto dto) {
        dto.setReservation(SecurityUtils.getUserId().toString());
        return baseMapper.listTrusteeship(dto);
    }

    @Override
    public int addTrusteeship(OldTrusteeship dto) {
//        OldStaff oldStaff = oldStaffMapper.selectById(dto.getStaff());
//        Assert.isTrue(ObjectUtil.isNotNull(oldStaff), "无此员工信息");
        dto.setId(IdUtil.simpleUUID());
        dto.setState("0");
        dto.setCreateTime(LocalDateTime.now());
        dto.setUpdateTime(LocalDateTime.now());
        dto.setReservation(SecurityUtils.getUserId().toString());
        dto.setReservationName(SecurityUtils.getUsername().toString());

        return baseMapper.insert(dto);
    }

    @Override
    public int updateTrusteeship(OldTrusteeship dto) {
        dto.setUpdateTime(LocalDateTime.now());
        return baseMapper.updateById(dto);
    }

    @Override
    public int deleteTrusteeship(String id) {
        return baseMapper.deleteById(id);
    }
}
